package com.chuang.bootplus.controller.user;


import com.chuang.bootplus.base.utils.ApiResponse;
import com.chuang.bootplus.po.LoginCodePO;
import com.chuang.bootplus.po.LoginPO;
import com.chuang.bootplus.po.SignInPO;
import com.chuang.bootplus.service.UserService;
import com.chuang.bootplus.vo.UserInfoVO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-11-04
 */
@RestController
@RequestMapping("/user")
@Api(tags = {"用户信息"})
@CrossOrigin
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class UserController {

    private final UserService userService;

    @PostMapping("login")
    @ApiOperation(httpMethod = "POST", value = "用户登陆")
    @ApiOperationSupport(includeParameters = {"LoginPO.username", "LoginPO.password"})
    public ApiResponse<UserInfoVO> userLogin(@RequestBody LoginPO po, HttpServletResponse response){
        return userService.login(po,response);
    }

    @PostMapping("signIn")
    @ApiOperation(httpMethod = "POST", value = "用户注册")
    @ApiOperationSupport(includeParameters = {"SignInPO.username", "SignInPO.password", "SignInPO.nickname"})
    public ApiResponse<Void> userSignIn(@RequestBody SignInPO po){
        return userService.signIn(po);
    }

    @PostMapping("loginPhone")
    @ApiOperation(httpMethod = "POST", value = "用户使用手机验证码登录")
    @ApiOperationSupport(includeParameters = {"SignInPO.username", "SignInPO.password", "SignInPO.nickname"})
    public ApiResponse<UserInfoVO> userLoginPhone(@RequestBody LoginCodePO po ,HttpServletResponse response){
        return userService.loginPhone(po,response);
    }

    @PostMapping ("logout")
    @RequiresAuthentication
    @ApiOperation(httpMethod = "POST", value = "用户退出")
    @ApiOperationSupport(includeParameters = {})
    public ApiResponse<Void> userlogout() {
       return userService.logout();
    }

}

